﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gol.Domain;

namespace Gol.UI.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            const int rows = 10;
            const int cols = 10;
            var gameOfLife = new GameOfLife(rows, cols);
            gameOfLife.Start(new int[,] {{  0, 0  }, {  0,  2 },  {  0,  3 },   {  0,  9 },
                                         {  1,  4 }, 
                                         {  2,  5 },  
                                         {  3,  5 },  
                                         {  4,  5 },  
                                         {  5,  5 }, 
                                         {  9,  0 }, {  9, 9 } });


            DumpGrid(gameOfLife.CellGrid);
            System.Console.WriteLine("");
            System.Console.WriteLine("press c");
            ConsoleKeyInfo key = System.Console.ReadKey(true);

            while (key.KeyChar == 'c')
            {
               gameOfLife.NextGeneration();
                DumpGrid(gameOfLife.CellGrid);
                System.Console.WriteLine("press c");
                key = System.Console.ReadKey(true);
            }


        }

        private static void DumpGrid(CellGrid grid)
        {
            for (int i = 0; i < grid.NumberOfRows; i++)
            {
                for (int j = 0; j < grid.NumberOfColums; j++)
                {
                    if (grid[i, j].IsAlive)
                    {
                        if (j == grid.NumberOfColums-1)
                        {
                            System.Console.WriteLine("X");
                        }
                        else
                        {
                            System.Console.Write("X");
                        }
                       
                    }
                    else
                    {
                        if (j == grid.NumberOfColums - 1)
                        {
                            System.Console.WriteLine(" ");
                        }
                        else
                        {
                            System.Console.Write(" ");
                        }
                    }
                }
            }
            System.Console.WriteLine();
        }
    }
}
